package com.dy.springcloud.service;

import com.dy.springcloud.entity.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

//openfeign的核心
@Component//直接注入。可以获取登录代理对象
@FeignClient(value = "seata-storage-micro-service")//服务提供集群的注册别名
public interface StorageService {

    //定义远程访问接口，@PostMapping("/storage/reduce")，和参数是服务提供集群的controller接口方法中复制的
    //调用url为 http://seata_storage_micro_service/storage/reduce

    //使用Feign客户端时，Service接口中的方法定义多个参数而没有正确指定请求体会报错
    // Feign默认情况下只能有一个未注解的参数作为请求体。，否则使用 @RequestParam
    @PostMapping("/storage/reduce")
    public Result reduce(@RequestParam("productId") Long productId,@RequestParam("nums") Integer nums);
}
